﻿package  
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.net.URLRequest;
	
	/**
	 * ...
	 * @author Neelts
	 */
	public class VKWrapper
	{
		
		static private var _wrapper:Object;
		
		static private var _present:Boolean = false;
		
		static private var _application:Object;
		static private var _external:Object;
		static private var _dispatcher:EventDispatcher;
		
		static public function init(wrapper:Object):void
		{
			if (wrapper) {
				_wrapper = wrapper;
				
				_application = _wrapper.application;
				_external = _wrapper.external;
				_dispatcher = _wrapper as EventDispatcher;
				
				_present = true;
				
			} else {
				
				trace('Error: Wrapper not available!');
			}
		}
		static public function get present():Boolean { return _present; }
		
		// Application
		
		// getters
		
		static public function get parameters():Object { return _application.parameters; }
		
		static public function get quality():String { return _application.quality; }
		static public function get scaleMode():String { return _application.scaleMode; }
		static public function get align():String { return _application.align; }
		static public function get frameRate():Number { return _application.frameRate; }
		static public function get stageWidth():Number { return _application.stageWidth; }
		static public function get stageHeight():Number { return _application.stageHeight; }
		
		// setters
		
		static public function set quality(value:String):void { _application.quality = value; }
		static public function set scaleMode(value:String):void { _application.scaleMode = value; }
		static public function set align(value:String):void { _application.align = value; }
		static public function set frameRate(value:Number):void { _application.frameRate = value; }
		
		
		// External
		
		static public const S_NO:uint = 0;
		static public const S_NOTIFICATIONS:uint = 1;
		static public const S_FRIENDS:uint = 2;
		static public const S_PHOTOS:uint = 4;
		static public const S_AUDIOS:uint = 8;
		static public const S_OFFERS:uint = 32;
		static public const S_QUESTIONS:uint = 64;
		static public const S_WIKI:uint = 128;
		
		static public function settingsHave(settings:uint, have:uint):Boolean { return uint(settings & have) == have; };
		
		static public function showInstallBox():void { _external.showInstallBox(); }
		static public function showSettingsBox(settings:uint):void { _external.showSettingsBox(settings); }
		static public function showInviteBox():void { _external.showInviteBox(); }
		static public function showPaymentBox(votes:Number):void { _external.showPaymentBox(votes); }
		static public function resizeWindow(width:uint, height:uint):void { _external.resizeWindow(width, height); }
		static public function scrollWindow(top:uint, speed:uint):void { _external.scrollWindow(top, speed); }
		static public function setTitle(title:String):void { _external.setTitle(title); }
		static public function setLocation(location:String):void { _external.setLocation(location); }
		static public function setNavigation(labels:Array, links:Array):void { _external.setNavigation(labels, links); }
		static public function navigateToURL(request:URLRequest):void { _external.navigateToURL(request); }
		
		// Events
		
		static public const APPLICATION_ADDED:String = 'onApplicationAdded';
		static public const SETTINGS_CHANGED:String = 'onSettingsChanged';		// properties available: settings
		static public const BALANCE_CHANGED:String = 'onBalanceChanged';		// properties available: balance
		static public const WINDOW_RESIZED:String = 'onWindowResized';		// properties available: width, height
		static public const LOCATION_CHANGED:String = 'onLocationChanged';		// properties available: location
		static public const WINDOW_BLUR:String = 'onWindowBlur';
		static public const WINDOW_FOCUS:String = 'onWindowFocus';
		static public const MOUSE_LEAVE:String = 'onMouseLeave';
		
		static public function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void { _dispatcher.addEventListener(type, listener, useCapture, priority, useWeakReference); }
		static public function dispatchEvent(event:Event):Boolean { return _dispatcher.dispatchEvent(event); }
		static public function hasEventListener(type:String):Boolean { return _dispatcher.hasEventListener(type); }
		static public function removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void { _dispatcher.removeEventListener(type, listener, useCapture); }
		static public function willTrigger(type:String):Boolean { return _dispatcher.willTrigger(type); }
		
	}

}